﻿
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>系统用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>
</head>
<body>
    <ul lay-bar="disabled" class="mWebBanner">
        <li class="layui-nav-item" style="float:left;">
            <button id="btn-update" type="button" name="btn_update" onclick="sureChoose()" class="buttonCss">
                确认权限
            </button>
        </li>
        <li class="layui-nav-item" style="float:left;margin-left:3%">
            <button id="btn-update" type="button" name="btn_update" onclick="cleanPower()" class="buttonCss">
                取消权限
            </button>
        </li>
        <li class="layui-nav-item" style="float:left;margin-left:3%">
            <button id="btn-sync" type="button" onclick="closeWin()" class="buttonCss">
                关闭页面
            </button>
        </li>
    </ul>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
               
                    <div class="layui-card-body layui-table-body" id="layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

<script>

    var rCode = "";
    var userCode = "";
    $(function () {
        userCode = decodeURI(getUrlVariable("userCode"));
        rCode = decodeURI(getUrlVariable("roleCode"));
        loadData();
    })

    var currPage = 1;//首先默认值为1，防止出错
    var groupCode = "";
    /**
    数据加载
    **/
    function loadData() {
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("qForm"));
            var dUrl = "../System/getDataList?dataType=pRole&condition=" + conditon;
            var table = layui.table;
            table.render({
                elem: '#list'
                , cols: [[ //标题栏
                    { type: 'radio' }
                    , { field: 'groupCode', title: '角色编码', width: 140 }
                    , { field: 'groupName', title: '角色名称', width: 130 }
                    , { field: 'memo', title: '备 注', width: 250 }
                    , { field: 'userName', title: '创建人', width: 90 }
                ]], done: function (res, curr, count) {
                    $("[data-field='id']").css('display', 'none');//隐藏列
                    currPage = curr;
                    $.each(res['data'], function (i, json) {
                        if (json["groupCode"] == rCode) {
                            $(".layui-table-view[lay-id='tData'] .layui-table-body tr[data-index =" + i + "] .layui-form-radio").click();
                        }

                    });

                }

                , url: dUrl
                , skin: 'row' //表格风格
                , even: true
                , page: true //是否显示分页
                , limits: [20, 30, 50]
                , limit: 20 //每页默认显示的数量
                , id: "tData"
            });
            table.on('radio(list)', function (obj) {
                var data = obj.data;
                groupCode = data.groupCode;

            });

        });
    }
    /**
    确认选择
    **/
    function sureChoose() {
        if (groupCode == "") {
            layer.msg("没有为当前用户选择权限角色"); return;
        }
        $.ajax({
            url: "../System/SaveUserRole",
            type: "post",
            data: { userCode: userCode, groupCode: groupCode },
            success: function (rsl) {
                if (rsl.result) {
                    layer.msg("权限设置成功", { icon: 1, time: 500, shade: 0.4 }, function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(data.message);
                }
            }
        });
    }
    function cleanPower() {
        $.ajax({
            url: "../System/cleanUserRole",
            type: "post",
            data: { userCode: userCode },
            success: function (rsl) {
                if (rsl.result) {
                    layer.msg("权限清除成功", { icon: 1, time: 500, shade: 0.4 }, function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
</script>